const titleKey = "title:";
const categoryKey = "category:";
const dateKey = "date:";
const topSep = "---";
const authorKey = "author:";
const sourceKey = "source:";

export function init(content) {
    var md = {
        topSummary: "",
        mainContent: "",
        title: "",
        category: [],
        date: "",
        author: "",
    }
    // 主要内容
    const index1 = content.indexOf(topSep);
    const index2 = content.indexOf(topSep, index1 + 1);
    md.mainContent = content.substring(index2 + topSep.length);
    // 顶部摘要
    md.topSummary = content.substring(topSep.length, index2);
    const titleIndex = md.topSummary.indexOf(titleKey);
    const categoryIndex = md.topSummary.indexOf(categoryKey);
    // 标题
    md.title = md.topSummary.substring(titleIndex + titleKey.length, categoryIndex);
    // 日期
    const dateIndex = md.topSummary.indexOf(dateKey);
    const authorIndex = md.topSummary.indexOf(authorKey);
    md.date = md.topSummary.substring(dateIndex + dateKey.length, authorIndex);
    // 分类
    const categoryList = md.topSummary.substring(categoryIndex + categoryKey.length, dateIndex);
    md.category = categoryList.split(",");
    // 作者
    const sourceIndex = md.topSummary.indexOf(sourceKey);
    md.author = md.topSummary.substring(authorIndex + authorKey.length, sourceIndex);

    return md;
}